﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Entity;
using ClassLibrary.Data;
using System.Data;

namespace ClassLibrary.DAO
{
    public class TblJobsDAO
    {
        DBService _db = null;
        public TblJobsDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable InsertUpdJob(TblJobs Jobs, int mode)
        {
            DataTable flag = null;
            try
            {
                flag = _db.ExeSP_DataTable("sp_TblJobs_InsUpd",
                    new string[] {"@JobID", "@CustomerIndex", "@DateBook", "@CurrentStatus", "@PhoneID", "@ExpectedCompletionDate", "@DateCompleted", 
							      "@RepairCharge", "@LPCharge", "@OtherCharge", "@SalesAmount", "@PaymentMethod", "@QuotationStatus", "@ApprovalStatus", "@FaultDescription","@mode" },
                    new object[] {Jobs.JobID, Jobs.CustomerIndex, Jobs.DateBook, Jobs.CurrentStatus, Jobs.PhoneID, Jobs.ExpectedCompletionDate, Jobs.DateComplete,
                                  Jobs.RepairCharge, Jobs.LPCharge, Jobs.OrtherCharge, Jobs.SalesAmount, Jobs.PaymentMethod, Jobs.QuotationStatus, Jobs.ApprovalStatus, Jobs.FaultDescription, mode},
                    CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }
        public DataTable GetJob(int JobID)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_JobList",
                    new string[] { "@JobID" },
                    new object[] { JobID }, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable reportJob1(int JobID)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_reportJob",
                    new string[] { "@JobID" },
                    new object[] { JobID }, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public List<JobRpt> ReportJob(int JobID)
        {
            List<JobRpt> ListJob = new List<JobRpt>();
            try
            {
               DataTable dt = _db.ExeSP_DataTable("sp_reportJob",
                    new string[] { "@JobID" },
                    new object[] { JobID }, CommandType.StoredProcedure);
               foreach (DataRow r in dt.Rows)
               {
                   JobRpt job = new JobRpt();
                   job.JobID = Convert.ToInt32(r["JobID"]);

                   ListJob.Add(job);
               }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ListJob;
        }
    }
}
